import React,{ Component } from "react";

class TodoItem extends Component {
	constructor(props){
		super(props)
		this.handleClick = this.handleClick.bind(this)
	}
	UNSAFE_componentWillReceiveProps(aa,bb){
		// console.log(aa);
		// console.log(this.props);
	}
	shouldComponentUpdate(nextProps, nextState) {
		if (nextProps.content !== this.props.content) {
		console.log("nextProps.content:", nextProps.content);
		console.log("this.props.content:", this.props.content);
			return true;
		}else {
			console.log("nextProps.content:", nextProps.content);
			console.log("this.props.content:", this.props.content);
			return false;
		}
	}
	handleClick(){
		//改变父组件中list的数据
		//子组件想和父组件通信，就要调用父组件传递过来的方法
		const { deleteFunction, index } = this.props;
		deleteFunction(index);
//		this.props.deleteFunction(this.props.index);//效果同上面两句的和
	}
	render() {
		console.log("child render");
		const { content } = this.props;
		return <li onClick={this.handleClick}>{ content }</li>
	}
}

export default TodoItem;
